import 'package:flutter/material.dart';

class BaseViewBar extends PreferredSize {
  Widget child;
  @override
  final Size preferredSize;

  BaseViewBar({this.preferredSize, this.child});

  @override
  Widget build(BuildContext context) {
    Widget current = child;
    if (child == null) {
      current = LimitedBox(
        maxWidth: 0.0,
        maxHeight: 0.0,
        child: ConstrainedBox(constraints: const BoxConstraints.expand()),
      );
    }
    return current;
  }
}

class BaseTitleBar extends StatelessWidget implements PreferredSizeWidget {
  String title;
  bool showLeading = true;
  List<Widget> actions;

  BaseTitleBar(this.title, {this.showLeading, this.actions});

  @override
  Widget build(BuildContext context) {
    return new AppBar(
      title: new Text(
        this.title,
        style: TextStyle(color: Colors.white),
      ),
      automaticallyImplyLeading: false,
      leading: showLeading == null || showLeading
          ? new IconButton(
              icon: Icon(Icons.arrow_back_ios),
              color: Colors.white,
              onPressed: () {
                Navigator.pop(context);
              },
            )
          : Text(""),
      brightness: Brightness.dark,
      elevation: 2.0,
      centerTitle: true,
      actions: this.actions,
    );
  }

  @override
  Size get preferredSize => throw UnimplementedError();
}
